﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public enum EGamePhase
{
    TITLE,
    CHOOSE_LEVEL,
    IN_GAME,
    RESULT,
}

public class GameApp : MonoBehaviour
{
    private static GameApp sGameApp;

    public PictureResultScript ResultPageScript;
    public GameObject Title;
    public PictureChooseScript ResultChooseScript;

    private static EGamePhase mGamePhase = EGamePhase.TITLE;      //先从这个开始，跳过title

    public static GameApp GetInstance()
    {
        return sGameApp;
    }

    void Awake()
    {
        sGameApp = this;
        PictureLogicScript.Create();
        Application.targetFrameRate = 60;
    }

    private void Start()
    {
        if(mGamePhase == EGamePhase.RESULT)
        {
            if(ResultPageScript != null)
            {
                ResultPageScript.gameObject.SetActive(true);
                ResultPageScript.ShowResult();
            }
        }
        else if(mGamePhase == EGamePhase.TITLE)
        {
            if(Title != null)
            {
                Title.SetActive(true);
            }
        }
    }

    void Update()
    {
        switch (mGamePhase)
        {
            case EGamePhase.TITLE:
                {
                    break;
                }
            case EGamePhase.CHOOSE_LEVEL:
                {
                    break;
                }
            case EGamePhase.IN_GAME:
                {
                    break;
                }
            case EGamePhase.RESULT:
                {
                    break;
                }
        }
    }

    public void TryStart()
    {
        if (mGamePhase == EGamePhase.CHOOSE_LEVEL)
        {
            mGamePhase = EGamePhase.IN_GAME;
            SceneManager.LoadScene("GameScene");
        }
    }

    public void TrySkipTitle()
    {
        if (mGamePhase == EGamePhase.TITLE)
        {
            mGamePhase = EGamePhase.CHOOSE_LEVEL;
            if (ResultChooseScript != null)
            {
                ResultChooseScript.gameObject.SetActive(true);
            }
        }
    }

    public void TryEnd()
    {
        if (mGamePhase == EGamePhase.IN_GAME)
        {
            mGamePhase = EGamePhase.RESULT;
            SceneManager.LoadScene("Main");
        }
    }

    public void TryBackToChoose()
    {
        if(mGamePhase == EGamePhase.RESULT)
        {
            mGamePhase = EGamePhase.CHOOSE_LEVEL;
            if (ResultChooseScript != null)
            {
                ResultChooseScript.gameObject.SetActive(true);
            }
            if (ResultPageScript != null)
            {
                ResultPageScript.gameObject.SetActive(false);
            }
        }
    }

    public EGamePhase GetPhase()
    {
        return mGamePhase;
    }
}
